﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;

namespace WcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    [ServiceBehavior (InstanceContextMode = InstanceContextMode.Single)]
    public class WcfCinemaService : IWcfCinemaService
    {
        private CtrBooking ctb = new CtrBooking();
        private CtrCinemaRoom ctcr = new CtrCinemaRoom();
        private CtrCustomer ctc = new CtrCustomer();
        private CtrEmployee cte = new CtrEmployee();
        private CtrMovie ctm = new CtrMovie();
        private CtrSeat cts = new CtrSeat();
        private CtrShowTime ctst = new CtrShowTime();
        private CtrTicket ctt = new CtrTicket();
        private GetReservedSeatsList rsl = new GetReservedSeatsList();
        

        #region Movie
        public List<Movie> ReadMovie(string title)
        {
            return ctm.Read(title);
        }

        public Movie ReadMovieById(int id)
        {
            return ctm.Read(id);
        }

        public List<Movie> ReadAllMovies()
        {
            return ctm.ReadAll();
        }

        public int InsertMovie(Movie movie)
        {
            return ctm.Insert(movie);
        }

        public int UpdateMovie(Movie movie)
        {
            return ctm.Update(movie);
        }

        public int DeleteMovie(int id)
        {
            return ctm.Delete(id);
        }
        public List<Movie> DateMovie(String date)
        {
            return ctm.DateMovie(date);
        }
        public Movie MovieObject(int id, string title, string description, double price, bool is3d, int length, int commercials, int trailer, string image)
        {
            return ctm.MovieObject(id, title, description, price, is3d, length, commercials, trailer, image);
        }
        #endregion

        #region Seat
        public Seat ReadSeat(int id)
        {
            return cts.Read(id);
        }

        public List<Seat> ReadAllSeats(int room)
        {
            return cts.ReadAll(room);
        }

        public void InsertSeat(Seat seat)
        {
            cts.Insert(seat);
        }

        public void UpdateSeat(Seat seat)
        {
            cts.Update(seat);
        }

        public void DeleteSeat(Seat seat)
        {
            cts.Delete(seat);
        }
        public Seat SeatObject(int row, int seatNumber, double price, bool handicap, bool legspace, int room)
        {
            return cts.SeatObject(row, seatNumber, price, handicap, legspace, room);
        }
        #endregion

        #region Ticket
        public List<Ticket> ReadAllTicket()
        {
            return ctt.ReadAll();
        }

        public List<Ticket> ReadTicket(Booking booking)
        {
            return ctt.Read(booking);
        }

        public List<Ticket> ReadTicketByShowTime(ShowTime showTime)
        {
            return ctt.Read(showTime);
        }

        public List<Ticket> ReadAllTickets(int id)
        {
            return ctt.ReadAll(id);
        }

        public void InsertTicket(Ticket tick)
        {
            ctt.Insert(tick);
        }
        public Ticket TicketObject(double ticketPrice, ShowTime showTime, Seat seat, Booking booked)
        {
            return ctt.TicketObject(ticketPrice, showTime, seat, booked);
        }
        #endregion

        #region ShowTime
        public ShowTime ReadShowTime(int id)
        {
            return ctst.Read(id);
        }

        public List<ShowTime> ReadShowTimeByMovie(Movie mov)
        {
            return ctst.Read(mov);
        }

        public List<ShowTime> ReadShowTimeByRoom(CinemaRoom room)
        {
            return ctst.Read(room);
        }

        public List<ShowTime> ReadShowTimeByDate(DateTime date)
        {
            return ctst.Read(date);
        }

        public List<ShowTime> ReadShowTimeByShowtime(ShowTime sht)
        {
            return ctst.Read(sht);
        }

        public int GetShowTimeID(ShowTime sht)
        {
            return ctst.GetID(sht);
        }

        public List<ShowTime> ReadAllShowTimes()
        {
            return ctst.ReadAll();
        }

        public void InsertShowTime(ShowTime showTime)
        {
            ctst.Insert(showTime);
        }
        public List<ShowTime> DateShowTimes(string date)
        {
            return ctst.DateShowTimes(date);
        }

        public void UpdateShowTime(ShowTime newTime, ShowTime oldTime)
        {
            ctst.Update(newTime, oldTime);
        }

        public void DeleteShowTime(ShowTime showTime)
        {
            ctst.Delete(showTime);
        }
        public ShowTime ShowTimeObject(DateTime date, Movie movie, double price, CinemaRoom room)
        {
            return ctst.ShowTimeObject(date, movie, price, room);
            
        }
        #endregion

        #region Employee
        public List<Employee> ReadEmployee(string fname, string lname, string phone)
        {
            return cte.Read(fname, lname, phone);
        }
        public int InsertEmployee(Employee emp)
        {
            return cte.Insert(emp);
        }

        public int DeleteEmployee(int id)
        {
            return cte.Delete(id);
        }

        public int UpdateEmployee(Employee emp)
        {
            return cte.Update(emp);
        }
        public Employee EmployeeObject(string phoneNo, string lname, string fname, bool isadmin, int id, bool isactive, List<Booking> bookings)
        {
            return cte.EmployeeObject(phoneNo, lname, fname, isadmin, id, isactive, bookings);
        }
        #endregion

        #region Customer
        public List<Customer> ReadCustomer(string phoneNumber)
        {
            return ctc.Read(phoneNumber);
        }

        public List<Customer> ReadAllCustomers()
        {
            return ctc.ReadAll();
        }

        public int InsertCustomer(Customer cust)
        {
            return ctc.Insert(cust);
        }

        public int DeleteCustomer(string phoneNumber)
        {
            return ctc.Delete(phoneNumber);
        }
        public Customer CustomerObject(string phoneNo, string name, string email, Booking booked)
        {
            return ctc.CustomerObject(phoneNo, name, email, booked);
        }
        #endregion

        #region Cinema
        public CinemaRoom ReadCinemaRoom(int id)
        {
            return ctcr.Read(id);
        }

        public List<CinemaRoom> ReadAllCinemaRooms()
        {
            return ctcr.ReadAll();
        }

        public int InsertCinemaRoom(CinemaRoom room)
        {
            return ctcr.Insert(room);
        }

        public int UpdateCinemaRoom(CinemaRoom room)
        {
            return ctcr.Update(room);
        }

        public int DeleteCinemaRoom(int id)
        {
            return ctcr.Delete(id);
        }
        public CinemaRoom CinemaRoomObject(int id, string screen, int maxSeats, int maxLengthSeats, List<Seat> seats, List<ShowTime> shows, int amount)
        {
            return ctcr.CinemaRoomObject(id, screen, maxSeats, maxLengthSeats, seats, shows, amount);
        }
        #endregion

        #region Booking
        public Booking ReadBookingById(int id)
        {
           return ctb.Read(id);
        }

        public List<Booking> ReadBooking(Customer customer)
        {
            return ctb.Read(customer);
        }

        public int InsertBooking(Booking booking)
        {
            return ctb.Insert(booking);
        }

        public int UpdateBooking(Booking booking)
        {
            return ctb.Update(booking);
        }

        public int BookingMaxID()
        {
            return ctb.BookingMaxID();
        }
        public void CheckBooking()
        {
            ctb.CheckBooking();
        }
        public Booking BookingObject(int id, double totalprice, int status, string customerphone)
        {
            return ctb.BookingObject(id, totalprice, status, customerphone);
        }

        public Booking CreateBooking(List<Ticket> tickets, Customer customer, int status)
        {
            return ctb.CreateBooking(tickets, customer, status);
        }

        public Booking CreateBookingFromSeats(ShowTime showTime, List<Seat> seats, Customer customer)
        {
            return ctb.CreateBookingFromSeats(showTime, seats, customer);
        }
        #endregion

        #region BookingList

        public List<Seat> ReservedListGet(ShowTime showTime)
        {
            return rsl.GetInternalSeats(showTime).GetSeatList();
        }

        public List<Seat> ReservedListAdd(ShowTime showTime, Seat seat)
        {
            rsl.GetInternalSeats(showTime).SelectSeat(seat);
            return rsl.GetInternalSeats(showTime).GetSeatList();
        }

        public void ReservedListRemove(ShowTime showTime, Seat seat)
        {
            rsl.GetInternalSeats(showTime).RemoveSeat(seat);
        }

        public void ReservedListPopulate(ShowTime showTime)
        {
            rsl.GetInternalSeats(showTime).PopulateSeats();
        }

        
        #endregion
    }
}
